<%@page import="com.netistate.pojo.ClientContact"%>
<%@page import="com.netistate.pojo.Sale"%>
<%@page import="com.netistate.pojo.Project"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="com.netistate.pojo.User"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>项目页面</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/default.css" />
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/common.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/js/table.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/plugin/msgbox/msgbox.js"></script>
    <script type="text/javascript"  src="${pageContext.request.contextPath}/jsp/project/project.js"></script>
    <style type="text/css">
		.overTd {table-layout:fixed}
		.overTd td{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;padding:0px}
    </style>
  </head>
  <body>
   <% String id = (String)request.getSession().getAttribute("projectid");
   	  Project p = (Project)request.getSession().getAttribute("selectProject");
   %>
   		
   		<div id="xtab">
			<a id="rightDiv0_tab" href="#" class='homelink ' onclick="lookSale(<%=id%>)"><span style="cursor:pointer;">服务记录表</span></a>
			<a id="rightDiv1_tab" href="#" class='homelink ' onclick="lookTechNote(<%=id%>)"><span style="cursor: pointer;">技术备忘录</span></a>
			<a id="rightDiv1_tab" href="#" class='homelink curren' onclick=""><span style="cursor: pointer;">客户信息表</span></a>
			<a id="rightDiv1_tab" href="#" class='homelink' onclick="lookDoc(<%=id%>)"><span style="cursor: pointer;">文档列表</span></a>
		</div>
   		
   		<div class="toolbar" >
   			<a href="javascript:;" class='buttonlink txbtip' style="font-size:14pt;font-family:微软雅黑;display:inline;color:red" title='当前项目'>当前位置：<%=p.getProjectName() %>→客户联系表</a>
   				<img width='16' height='16' src='${pageContext.request.contextPath}/images/common/elbow-line.gif'/>
		    	<img width='16' height='16' src='${pageContext.request.contextPath}/images/common/elbow-line.gif'/><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/elbow-line.gif'/>
		    <a href="#" class='buttonlink txbtip' title='添加客户联系人' onclick="addClient('',<%=id%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/plus.png'/>添加客户联系人</a>
		    	<img width='16' height='16' src='${pageContext.request.contextPath}/images/common/elbow-line.gif'/><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/elbow-line.gif'/>
		</div>
		
		<form id="findAllClientContact" action="findAllClientContact.action">
			<input type="hidden" name="pid" value="<%=id%>"/>
		</form>
		
   		<div id="show_project_clients" style="width:100%;height:95%; overflow-y:scroll; border:1px solid;" >
			<table id="dArticleList" width="100%" border="0" cellpadding="0" cellspacing="1"  class="resizable overTd">
				<thead>
					<tr class="fixHead">
						<td  class="td1" style="cursor:pointer" width="20%">公司</td>
						<td  class="td1" style="cursor:pointer" width="15%">联系人名称</td>
						<td  class="td1" style="cursor:pointer" width="20%">地址</td>
						<td  class="td1" style="cursor:pointer" width="10%">电话</td>
						<td  class="td1" style="cursor:pointer" width="10%">邮件</td>
						<td  class="td1" width="10%">编辑</td>
						<td  class="td1" width="10%">删除</td>
					</tr>
				</thead>
				<%	List<ClientContact> list = new ArrayList<ClientContact>();
					//用条件查list从request取值
					List<ClientContact> ccList = (List<ClientContact>)request.getAttribute("ccList");
					if(ccList == null){
						//查全部的从session取值
						list = (List<ClientContact>)request.getSession().getAttribute("clientContactList");
					} else {
						list = ccList;
					}
					for(ClientContact c : list){
					%>
					<tr onMouseOver= "this.bgColor   =   '#cccccc '; "   onMouseOut= "this.bgColor   =   '#FFFFFF'; " >  
						<td title="<%=c.getCompany() %>" align="center" class="td2 txbtip" >
			       			<%if(c.getCompany() == null || "null".equals(c.getCompany())){ %>
			       			-
			       			<%}else{ %>
			       			<%=c.getCompany()%>
			       			<%} %>
			       		</td>
			       		<td title="<%=c.getContactName()%>" align="center" class="td2 txbtip" >
			       			<%if(c.getContactName() == null){ %>
			       			-
			       			<%}else{ %>
			       			<%=c.getContactName()%>
			       			<%} %>
			       		</td>
			       		<td title="<%=c.getAddress() %>" align="center" class="td2 txbtip" >
			       			<%if(c.getAddress() == null || "null".equals(c.getAddress())){ %>
			       			-
			       			<%}else{ %>
			       			<%=c.getAddress()%>
			       			<%} %>
			       		</td>
			       		<td title="<%=c.getTel() %>" align="center" class="td2 txbtip" >
			       			<%if(c.getTel() == null){ %>
			       			-
			       			<%}else{ %>
			       			<%=c.getTel()%>
			       			<%} %>
			       		</td>
			       		
			       		<td title="<%=c.getEmail() %>" align="center" class="td2 txbtip" >
			       			<%if(c.getEmail() == null){ %>
			       			-
			       			<%}else{ %>
			       			<%=c.getEmail()%>
			       			<%} %>
			       		</td>
				          <td align="center" class="td2 txbtip">
						     <a href="#" class='buttonlink txbtip' title='修改' onclick="editClient(<%=c.getId()%>)"><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/edit.png'/></a>
					      </td>
					      <td align="center" class="td2 txbtip">
						      <a href="#" class='buttonlink txbtip' title='删除' onclick="delClient('<%=c.getId()%>','你确定要删除？')" ><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/delete.png'/></a>
					      </td>
					</tr>	
				  <%}%>	
			</table>
		</div>
   	<script type="text/javascript">
   	
   		//刷新
   		function refreshCC(){
   			document.getElementById("findAllClientContact").submit();
   		};
   	
   		//删除客户接口人
   		function delClient(projectClientId){
   			PigossMsg.confirm("确定要删除此联系人吗？",null,function yesHandler(){delContact(projectClientId)},function noHandler(){});
   			
   		};
   		//删除接口人
   		function delContact(projectClientId){
   			AjaxUtil.request({
				url : 'delContactClient.action',
				params : {projectClientId:projectClientId},
				success : function(responseText){
					refreshCC();
				},
				failure : function(){
				}
			});
   		};
   		
   		//编辑客户接口人
   		function editClient(projectClientId){
   			AjaxUtil.request({
				url : 'selectContactClient.action',
				params : {projectClientId:projectClientId},
				success : function(responseText){
					PigossMsg.show("${pageContext.request.contextPath}/jsp/project/editClient.jsp?id="+projectClientId,"编辑项目下的客户联系人",380,250,"EditClientContact.editContactClient()");
				},
				failure : function(){
				}
			});
   		
   		};
   	
  		//切换项目下的技术备忘录
		function lookTechNote(projectTechNoteId){
			AjaxUtil.request({
				url : 'look_project_techNote.action',
				params : {projectTechNoteId:projectTechNoteId},
				success : function(responseText){
					window.parent.document.getElementById("mainFrame").src="${pageContext.request.contextPath}/jsp/project/project_techNote.jsp?id="+projectTechNoteId;
				},
				failure : function(){
				}
			});
  		};
   		
   		//切换项目下的客户信息表
   		function lookSale(id){
   			AjaxUtil.request({
				url : 'selectProject.action',
				params : {id:id},
				success : function(responseText){
					window.parent.document.getElementById("mainFrame").src="${pageContext.request.contextPath}/jsp/project/project_id.jsp?id="+id;
				},
				failure : function(){
				}
			});
   		};
   		
   		//切换项目下的文档列表
   		function lookDoc(id){
   			AjaxUtil.request({
				url : 'look_project_doc.action',
				params : {id:id},
				success : function(responseText){
   					window.parent.document.getElementById("mainFrame").src="${pageContext.request.contextPath}/jsp/project/project_doc.jsp?id="+id;
				},
				failure : function(){
				}
			});
   		};
   		
   		//添加项目接口人
   		function saveClientContact(){
   			var id = document.getElementById("pid").value;
   			var contactNames = document.getElementsByName("contactName");
   			var tels = document.getElementsByName("tel");
   			var emails = document.getElementsByName("email");
   			var companys = document.getElementsByName("company");
   			var addresss = document.getElementsByName("address");
   			for(var i = 0; i<contactNames.length;i++){
   				var contact = contactNames[i];
   				var tel = tels[i];
   				var email = emails[i];
   				var company = companys[i];
   				var address = addresss[i];
   				
   				
   				if(contact.value==0||contact.value==''){
				   PigossMsg.alert("联系人成么不能为空或者空格！");
				   return;
				}
				if(company.value==0||company.value==''){
				   PigossMsg.alert("联系人公司不能为空或者空格！");
				   return;
				}
				
				if(tel.value==0||tel.value==''){
				   PigossMsg.alert("电话不能为空或者空格！");
				   return;
				}
				if(email.value==0||email.value==''){
				   PigossMsg.alert("电子邮件不能为空或者空格！");
				   return;
				}
				/* if(tel.value !=""){
					 var isExit = false;
					 var partten = /^0(([1-9]\d)|([3-9]\d{2}))\d{8}$/;
					 if (partten.test(tel.value)) {
						 //alert("是电话号码");
						 isExit = true;
					 }
					 if(/^13\d{9}$/.test(tel.value)||(/^15[0-35-9]\d{8}$/.test(tel.value))||(/^18[0-9]\d{8}$/.test(tel.value))){
						 isExit = true;
					 }
					 if(isExit){
						 PigossMsg.alert("联系电话格式不正确！");
						 return;
					 }
				} */
				if(email !=""){
					
					var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
					if (!(filter.test(email.value))){
							PigossMsg.alert("您的电子邮件格式不正确！");
						return;
					}
				} 
   				AjaxUtil.request({
					url : 'add_project_client.action',
					params : {id:id,contactName:contact.value,address:address.value,tel:tel.value,company:company.value,email:email.value},
					success : function(responseText){
						refreshCC();
					},
					failure : function(){
						PigossMsg.alert("添加失败!");
					}
				});
   			};
   			//refreshCC();
			imgCloseShow();
   		}
   		
   		//弹出添加客户接口人窗口
   		function addClient(){
   			var butHTML = "<a href=\"javascript:saveClientContact();\" class='buttonlink txbtip' title='保存'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/save.gif'/><p>保存</p></a><img src='${pageContext.request.contextPath}/images/common/shux.gif' class='split'/><a href=\"javascript:moreValue();\" class='buttonlink txbtip' title='更多联系人'><img width='16' height='16' src='${pageContext.request.contextPath}/images/common/add.gif'/><p>更多联系人</p></a>";
			PigossMsg.showWin("${pageContext.request.contextPath}/jsp/project/addClient.jsp","添加项目下的客户联系人",580,380,butHTML); 
   		};
   		
   		//删除一个联系人框
   		function deleteClientDiv(obj){
   		
   			var idiv = $('mydiv');
   			var totalnum = $('metric_count');
   			var length = parseInt(totalnum.value);
   			var objs = idiv.getElementsByTagName('div');
   			var d = obj.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement;
   			if(objs.length < 2){
   				PigossMsg.alert("联系人至少为一个！");
   				return;
   			}else{
   				d.parentElement.removeChild(d);
   			};
   		};
   		
   		
   		//再加一个联系人框
   		function moreValue(){
			var totalnum = $('metric_count');
			var idiv = $('mydiv');
			var length = parseInt(totalnum.value);
			
			var d = document.createElement('div');
			var objs = idiv.getElementsByTagName('div');
			if(objs.length > 0){
				d.innerHTML = objs[objs.length-1].innerHTML;
			}
			idiv.appendChild(d);
			totalnum.value = length+1;
   		};
   		
   		//点击查询技术备忘录
   		function selectTechNote(id){
   			AjaxUtil.request({
				url : 'selectTechNote.action',
				params : {id:id},
				success : function(responseText){
					window.document.getElementById("changePage").src="${pageContext.request.contextPath}/jsp/project/project_techNote.jsp?id="+id;
				},
				failure : function(){
					PigossMsg.alert("查询技术备忘录失败！");
				}
			});
   		};
   		
   		initTableWidget('dArticleList',['S','S',"S",'S','S','S',false]);
   	
	</script>
   
   
  </body>
</html>
    
    
    
